home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / basic / amiblitz_ful.lha / AmiBlitz2 / Examples / smartfold.ab2 < prev    next >
Encoding:
Text File  |  2002-12-27  |  5.7 KB  |  188 lines

  1. vsyncon=0   ;switch on if you want vsync (no tearing visible)
  2. #scrolling=0 ;set to 1 if you check speed when you scroll the background
  3. optimize 7;
  4.  
  5. ;Statement error {_text.s}           ; enable this statement if you don't have error.include !
  6. ;SHARED image_errcnt.l
  7. ;If image_errcnt Then Statement Return
  8. ;image_errcnt+1
  9. ;n.l = Request("ERROR:",_text.s,"OK")
  10. ;End Statement
  11. ;
  12. ;A little demo of moving things using the Blit command...
  13. ; the image.res must inlcude in compileroptions to use this functions
  14. WBStartup
  15. ;create a 'ball' type variable
  16. ;
  17. NEWTYPE.ball
  18. x.q
  19. y
  20. xs
  21. ys
  22. End NEWTYPE
  23.  DEFTYPE.l
  24. ;dimension a 'List' of 'balls'
  25. Dim List balls.ball(50)
  26. !image_include:
  27.  
  28. ;a beginning of directblit ignore it ***********************************
  29. ;@@1
  30. Macro image_blitmask2 ;{image,x,y,mode} if mode=1 blit non rectangle objects
  31. Statement image_blitmask2{image.l,x.l,y.l,mode.l}
  32. SHARED imagedat(),imgtags()
  33. USEPATH imagedat(image)
  34. If \bitmap_ptr=0        ;initialize all
  35.    If \pic_ptr
  36.      *win._Window = Peek.l(Addr Window(Used Window))
  37.      If *win=0 Then error {"Tried to blit into a non-existing window !"}:Statement Return
  38.      *scr._Screen = Peek.l(Addr Screen(Used Screen))
  39.      If *scr=0 Then  error{"Tried to blit into a non-exisiting screen !"}:Statement Return
  40.      If \drawhandle Then ReleaseDrawHandle_ \drawhandle : \drawhandle = False
  41.      ;*vp._ViewPort = ViewPort(Used Screen)
  42.      \drawhandle = ObtainDrawHandleA_ (\psm_ptr,RastPort(Used Window),*scr\_ViewPort\ColorMap, #TAG_DONE)
  43.      If \drawhandle=0 Then error{"No draw handle"}:Statement Return
  44.      If DoPictureMethodA_(\pic_ptr,#PICMTHD_CREATEALPHAMASK,0)=0
  45.      error {"Cannot create alpha mask (work only on 24bit image) !"}
  46.      Statement Return
  47.      End If
  48.      width.l=((\img_width+15)LSR 4)ASL 1
  49.      \mask_ptr=AllocMem((width*\img_height)+32,$10000)
  50.      size.l=width*\img_height
  51.       If \mask_ptr=0 Then error{"Cannot find MaskMem !"}:Statement Return
  52.       If CreatePictureMaskA_(\pic_ptr,\mask_ptr,width,Tags(@@
  53.           #GGFX_Ratio,2))=0
  54.           error {"Cannot create Mask !"}
  55.           Statement Return
  56.           End If
  57.      \bitmap_ptr=CreatePictureBitMapA_(\drawhandle,\pic_ptr,0)
  58.   Else
  59.   error {"Uninitialisized image/window/screen !"}
  60.   End If
  61. End If
  62. If Peek.l(Addr Window(Used Window))
  63.  
  64.    w=\img_width
  65.    h=\img_height
  66.    If x>799 Then Statement Return
  67.    If y>599 Then Statement Return
  68.    If w+x>799 Then w=799-x
  69.    If h+y>599 Then h=599-y
  70.    If w<=0 Then Statement Return
  71.    If h<=0 Then Statement Return
  72.    m.l=\mask_ptr
  73.    *srcbm._BitMap=\bitmap_ptr
  74.    *dstbm._BitMap=Peek.l(RastPort(Used Window)+4)
  75.    d.l=*dstbm._BitMap\Planes
  76.    s.l=*srcbm._BitMap\Planes
  77.    d=*dstbm._BitMap\BytesPerRow*y+d+x*2
  78.    width.l=((\img_width+15)LSR 4)ASL 1
  79.    For i=1 To h
  80.    GetD0 w:MOVE.l d0,d1
  81.    GetD0 s:MOVE.l d0,a0
  82.    GetD0 d:MOVE.l d0,a1
  83.    GetD0 m:MOVE.l d0,a2
  84.    MOVEQ #31,d3
  85.    MOVE.l (a2)+,d2
  86. label`@
  87.    BTST.l d3,d2
  88.    BEQ l2`@
  89.    MOVE.w (a0),(a1)
  90. l2`@ ADDQ.l #2,a0
  91.      ADDQ.l #2,a1
  92.    SUBQ.l #1,d3
  93.    BGE l5`@
  94.    MOVE.l (a2)+,d2
  95.    MOVEQ #31,d3
  96. l5`@
  97.    DBF d1,label`@
  98.    ;For i2=1 To w Step 2
  99.    ;Poke.w d+i2,Peek.w (s+i2)
  100. ;   Next
  101.    s+*srcbm._BitMap\BytesPerRow
  102.    d+*dstbm._BitMap\BytesPerRow
  103.    m+width
  104.    Next
  105.      ;BltMaskBitMapRastPort_ \bitmap_ptr,0,0,RastPort(Used Window),x,y,\img_width,\img_height,$c0,\mask_ptr
  106. Else
  107.      error {"Tried to blit into a non-existing window "}
  108. End If
  109. End Statement
  110. End Macro
  111. ;@@0
  112. ;************************************* end of not used
  113. !image_blitmask2:
  114.  
  115. !screen_ {0,"","ram:prefsfile",1}:If !screen_id=0 Then End  ;for display
  116. width=!screen_width
  117. height=!screen_height
  118. Window 0,0,0,width,height,$800,"",0,1
  119. succ=image_load  {1,"amiga1000.jpg"}
  120. succ=image_load  {0,"ball.iff"}
  121. image_blit{1,0,0} ;to set the palette for 8bit screens
  122.  InitShape 0,16,16,2
  123.  WPointer 0          ;set a unvisible mousepointer
  124. !screen_ {1,"","ram:prefsfile",0}:If !screen_id=0 Then End  ;for render
  125.  ;a second screen for doublebuffer
  126. Window 1,0,0,width,height,$800,"",0,1 ;second window
  127. !screen_ {2,"","ram:prefsfile",0}:If !screen_id=0 Then End ;screen for background
  128.  
  129. Window 2,0,0,width,height,$800,"",0,1 ;window to store backgroundimage
  130. image_blit{1,0,0}  ;blit the backgroundimage in window
  131. ;keep adding items to list until list full
  132. ;
  133. While AddLast(balls())
  134.   balls()\x=Rnd(width-30)+15,Rnd(height-30)+15,(Rnd-.5)*20+1,(Rnd-.5)*20+1
  135.   ;balls()\x=20,10,1,1
  136. Wend
  137.  
  138.   ShowScreen 0
  139. ;while mouse button not hit..
  140. ;
  141. While Joyb(0)=0
  142.  
  143.   If vsyncon VWait        ;can enable if you dont like tearing
  144.                           ;but most time this is unvisibly
  145.   Use Screen 1 ;copy all from screen 1 to window 0
  146.   Use Window 0
  147.   image_blitblock{0,0,0,0,0,0}
  148.   CNIF #scrolling>0
  149.   Use Window 2
  150.   WScroll 0,0,width,height,1,1 ;scroll the background
  151.   CEND
  152.   Use Window 1 ;set the renderwindow to 1
  153.   ;start at first item in list
  154.   ;
  155.   ResetList balls()
  156.   ;WCls
  157.   Use Screen 2         ;use the backgroundimage from screen 2
  158.                        ;screennum is source
  159.                        ;windowsnum is destination
  160.   image_blitblock {0,0,0,0,0,0}     ;blit whole backgroundimage
  161.   WLocate 220,55
  162.   If res<5 Then res=5
  163.   CNIF #scrolling=0    ;use textbackgroundcolor when scroll to read fps better
  164.   WJam 0               ;dont use textbackgroundcolor
  165.   CEND
  166.   NPrint "fps  ",50/(res LSR 2),"    ",num
  167.   ;wait for vertical blank
  168.   ;
  169.   ;Delay_(1)
  170.  
  171.   ;while more items to come...
  172.   ;
  173.   While NextItem(balls())
  174.     balls()\x+balls()\xs
  175.     balls()\y+balls()\ys
  176.     ;reverse direction if ball gets to edge of bitmap
  177.     ;
  178.     If balls()\x<10 OR balls()\x>width Then balls()\xs=-balls()\xs
  179.     If balls()\y<10 OR balls()\y>height Then balls()\ys=-balls()\ys
  180.     image_blitmask{0,balls()\x,balls()\y,1} ;draw balls
  181. 'l1    BTST #6,$dff016
  182.     BEQ 'l1
  183.   Wend
  184.   count+1
  185.   If count=4 Then count=0:res=Timer:ResetTimer
  186. Wend
  187. End  ;important allow autofree
  188.